//
//  UIBarButtonItem+Item.m
//  BaiSiProject
//
//  Created by lshenrong on 16/7/4.
//  Copyright © 2016年 lshenrong. All rights reserved.
//

#import "UIBarButtonItem+Item.h"

@implementation UIBarButtonItem (Item)
//高亮状态
+(instancetype)itemWithimage :(UIImage *)image highlightImage:(UIImage *)highlightImage Target:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    
    
    //    self.navigationItem.titleView=imageView;
    //设置左边的item,按钮用customView
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:image forState:UIControlStateNormal];
    [leftBtn setImage:highlightImage forState:UIControlStateHighlighted];
    //出现一个bug,按钮的有效点击范围过大
    [leftBtn addTarget:target action:action  forControlEvents:controlEvents];
    [leftBtn sizeToFit];
    
    UIView *btnView=[[UIView alloc] initWithFrame:leftBtn.bounds];
    [btnView addSubview:leftBtn];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btnView];
    
    
}
//选中状态
+(instancetype)itemWithimage :(UIImage *)image selImage:(UIImage *)selImage Target:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    
    
    //    self.navigationItem.titleView=imageView;
    //设置左边的item,按钮用customView
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:image forState:UIControlStateNormal];
    [leftBtn setImage:selImage forState:UIControlStateSelected];
    //出现一个bug,按钮的有效点击范围过大
    [leftBtn addTarget:target action:action  forControlEvents:controlEvents];
    [leftBtn sizeToFit];
    
    UIView *btnView=[[UIView alloc] initWithFrame:leftBtn.bounds];
    [btnView addSubview:leftBtn];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btnView];
    
    
}
//按钮带文字
+(instancetype)itemWithimage :(UIImage *)image highlightImage:(UIImage *)highlightImage Target:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents string:(NSString *)string
{
    
    
    //设置左边的item,按钮用customView
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:image forState:UIControlStateNormal];
    [leftBtn setImage:highlightImage forState:UIControlStateHighlighted];
    //设置文字
    [leftBtn setTitle:string forState:UIControlStateNormal];
    [leftBtn setTitle:string forState:UIControlStateHighlighted];
    //设置按钮位置和文字颜色
    [leftBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    leftBtn.contentEdgeInsets=UIEdgeInsetsMake(0, -18, 0, 0);
    //出现一个bug,按钮的有效点击范围过大
    [leftBtn addTarget:target action:action  forControlEvents:controlEvents];
    [leftBtn sizeToFit];
    
    UIView *btnView=[[UIView alloc] initWithFrame:leftBtn.bounds];
    [btnView addSubview:leftBtn];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btnView];
    
    
}



@end
